package com.lxk.controller;

import com.lxk.pojo.Contact;
import com.lxk.service.ContactSevice;
import com.lxk.vo.PageModel;
import com.lxk.vo.result.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * @author JohnSoybean
 * @create 2020/4/9 10:08
 * @description
 */
@Controller
public class ContactController {
    private Logger log = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private ContactSevice cs;


    /**
     * 加盟信息列表展示
     * @param req
     * @param model
     * @param pageIndex
     * @param num
     * @param totalPages
     * @return
     */
    @GetMapping("/contact")
    public String toContact(HttpServletRequest req, Model model,
                            Integer pageIndex, Integer num, Integer totalPages,
                            Integer sort, Integer order) {
        if (null == pageIndex) {
            pageIndex = 1;
        }
        if (null == num) {
            num = 15;
        }
        if (null == totalPages) {
            totalPages = cs.getContactPages(num);
        }
        PageModel<Contact> contacts = cs.selContactPage(pageIndex, num, totalPages, sort, order);
        model.addAttribute("data", contacts);
        return "contact";
    }

    /**
     * 获取加盟信息
     * @param contactId
     * @return
     */
    @GetMapping("/contact/query")
    @ResponseBody
    public Result<Contact> getContactInfo(Integer contactId) {
        Contact contact = cs.selContactById(contactId);
        return Result.success(contact);
    }

    /**
     * 标记已处理
     * @param contactId
     * @return
     */
    @GetMapping("/contact/handle")
    @ResponseBody
    public Result<Integer> markAsHandled(Integer contactId) {
        cs.markContactHandled(contactId);
        return Result.success(1);
    }


}
